home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 127 / PC Guia 127.iso / Software / Produtividade / OpenOffice.org 2.0.1 / openofficeorg4.cab / test_doctest2.py < prev    next >
Text File  |  2005-11-19  |  2KB  |  109 lines

  1. """A module to test whether doctest recognizes some 2.2 features,
  2. like static and class methods.
  3.  
  4. >>> print 'yup'  # 1
  5. yup
  6. """
  7.  
  8. from test import test_support
  9.  
  10. class C(object):
  11.     """Class C.
  12.  
  13.     >>> print C()  # 2
  14.     42
  15.     """
  16.  
  17.     def __init__(self):
  18.         """C.__init__.
  19.  
  20.         >>> print C() # 3
  21.         42
  22.         """
  23.  
  24.     def __str__(self):
  25.         """
  26.         >>> print C() # 4
  27.         42
  28.         """
  29.         return "42"
  30.  
  31.     class D(object):
  32.         """A nested D class.
  33.  
  34.         >>> print "In D!"   # 5
  35.         In D!
  36.         """
  37.  
  38.         def nested(self):
  39.             """
  40.             >>> print 3 # 6
  41.             3
  42.             """
  43.  
  44.     def getx(self):
  45.         """
  46.         >>> c = C()    # 7
  47.         >>> c.x = 12   # 8
  48.         >>> print c.x  # 9
  49.         -12
  50.         """
  51.         return -self._x
  52.  
  53.     def setx(self, value):
  54.         """
  55.         >>> c = C()     # 10
  56.         >>> c.x = 12    # 11
  57.         >>> print c.x   # 12
  58.         -12
  59.         """
  60.         self._x = value
  61.  
  62.     x = property(getx, setx, doc="""\
  63.         >>> c = C()    # 13
  64.         >>> c.x = 12   # 14
  65.         >>> print c.x  # 15
  66.         -12
  67.         """)
  68.  
  69.     def statm():
  70.         """
  71.         A static method.
  72.  
  73.         >>> print C.statm()    # 16
  74.         666
  75.         >>> print C().statm()  # 17
  76.         666
  77.         """
  78.         return 666
  79.  
  80.     statm = staticmethod(statm)
  81.  
  82.     def clsm(cls, val):
  83.         """
  84.         A class method.
  85.  
  86.         >>> print C.clsm(22)    # 18
  87.         22
  88.         >>> print C().clsm(23)  # 19
  89.         23
  90.         """
  91.         return val
  92.  
  93.     clsm = classmethod(clsm)
  94.  
  95. def test_main():
  96.     from test import test_doctest2
  97.     EXPECTED = 19
  98.     f, t = test_support.run_doctest(test_doctest2)
  99.     if t != EXPECTED:
  100.         raise test_support.TestFailed("expected %d tests to run, not %d" %
  101.                                       (EXPECTED, t))
  102.  
  103. # Pollute the namespace with a bunch of imported functions and classes,
  104. # to make sure they don't get tested.
  105. from doctest import *
  106.  
  107. if __name__ == '__main__':
  108.     test_main()
  109.